package cn.web.web_module.updateweb;

import cn.itcast.pojo.*;
import cn.itcast.service.UserService;
import cn.itcast.service.orderService;
import cn.itcast.util.ResponseEntity;
import cn.message.service.IEarningsService;
import cn.message.service.IHorsemanService;
import cn.message.service.adminService;
import cn.web.web_module.service.AdminRelevantService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 小松
 * @title: AdminRelevantController
 * @projectName dhn
 * @description: TODO
 * @date 2020/6/22 10:35
 */

@RestController
@RequestMapping("/updateAdmin")
@Api(value = "查看当前账户的推广")
public class AdminRelevantController {

    @Resource
    private adminService adminService;

    @Resource
    private UserService userService;

    @Resource
    private IEarningsService earningsService;

    @Resource
    private orderService orderService;

    @Resource
    private AdminRelevantService adminRelevantService;


    @RequestMapping("/addAdmin")
    public void addAdmim(@RequestParam admin admin,Integer roleId){
        adminService.SavaAdmin(admin);

    }

    /**
     *功能：任何openId查看一级推广伙伴
     * @author 张松
     * @date 2020/6/23
      * @param openId
     * @return cn.itcast.util.ResponseEntity
     */
    @RequestMapping("/getPromotionManagementOne")
    @ApiOperation(value = "查看当前用户的一级推广伙伴",response = Object.class)
    @ApiImplicitParam(paramType = "query",name = "openId",value = "用户id",required = true)
    @ApiResponse(code = 400,message = "参数没有填好",response = String.class)
    public ResponseEntity  getPromotionManagementOne(@ApiParam(value = "用户openid") String openId,Integer pageNum,Integer pageSize){
        try {
            Map<String, Object> promotionManagement = userService.getPromotionManagementOne(openId,pageNum,pageSize);
            return new ResponseEntity(promotionManagement);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }


    /**
     *功能：任何openId查看推广伙伴
     * @author 张松
     * @date 2020/6/23
     * @param openId
     * @return cn.itcast.util.ResponseEntity
     */
    @RequestMapping("/getPromotionManagementTwo")
    @ApiOperation(value = "查看当前用户的二级推广伙伴",response = Object.class)
    @ApiImplicitParam(paramType = "query",name = "openId",value = "用户id",required = true)
    @ApiResponse(code = 400,message = "参数没有填好",response = String.class)
    public ResponseEntity  getPromotionManagementTwo(@ApiParam(value = "用户openid") String openId,Integer pageNum,Integer pageSize){
        try {
            Map<String, Object> promotionManagement = userService.getPromotionManagementTwo(openId,pageNum,pageSize);
            return new ResponseEntity(promotionManagement);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }


    /**
     *功能：任何openId查看全部的收益
     * @author 张松
     * @date 2020/6/23
      * @param openId
     * @return cn.itcast.util.ResponseEntity
     */
    @RequestMapping("/getPromoteMoney")
    public ResponseEntity getPromoteMoney(String openId){
        try{
            List<earnings> allProfit = earningsService.getAllProfit(openId);
            return new ResponseEntity(allProfit);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }


    /**
     *
     * @Description:  查看昨天新增用户人数和下单详情
     *
     * @auther:   张松
     * @date: 12:00 2020/6/25
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @RequestMapping("/getYesterdayAdduserAndOrder")
    public ResponseEntity getYesterdayAdduserAndOrder(){
        try {
            Map<String, Object> yesterdayAdduserAndOrder = adminRelevantService.getYesterdayAdduserAndOrder();
            return new ResponseEntity(yesterdayAdduserAndOrder);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity().error_300();
    }

    /**
     *
     * @Description:  查看全部日期的新增用户人数和下单详情
     *
     * @auther:   张松
     * @date: 12:00 2020/6/25
     * @param: []
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @GetMapping("getEveryDayAdduserAndOrder")
    public ResponseEntity getEveryDayAdduserAndOrder(){
        Map<String, Object> everyDayAddUserAndOrder = adminRelevantService.getEveryDayAddUserAndOrder();
        try{
            return new ResponseEntity(everyDayAddUserAndOrder);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity("数据为空,重新查看").error_300();
    }


    /**
     *
     * @Description: 查看小伙伴的订单
     *
     * @auther: 张松
     * @date: 9:01 2020/7/9
     * @param: [openId, pageNum, pageSize]
     * @return: cn.itcast.util.ResponseEntity
     *
     */
    @PostMapping("selectPartnerOrder")
    public ResponseEntity selectPartnerOrder(String openId,Integer pageNum,Integer pageSize){
        PageInfo pageInfo = adminRelevantService.selectPartnerOrder(openId,pageNum,pageSize);
        try{
            if (!pageInfo.getList().isEmpty()||pageInfo.getList().size()!=0)
                return new ResponseEntity(pageInfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ResponseEntity("推广的小伙伴还没有下订单").error_300();
    }


    /**
     *
     * @Description: 根据传输的条件查询订单
     *
     * @auther: 张松
     * @date: 15:31 2020/7/7
     * @param: [order]
     * @return: java.util.List<cn.itcast.pojo.order>
     *
     */
        @PostMapping("selectStateAndNumberAndUserName")
        public ResponseEntity selectStateAndNumberAndUserName(@RequestBody order order,Integer pageNum,Integer pageSize){
            PageInfo pageInfo = adminRelevantService.selectStateAndNumberAndUserName(order, order.getOpenId(), pageNum, pageSize);
            try{
                if (!pageInfo.getList().isEmpty()||pageInfo.getList().size()!=0)return new ResponseEntity(pageInfo);
            }catch (Exception e){
                e.printStackTrace();
            }
            return new ResponseEntity("没有查询到订单").error_300();
    }


}
